package com.gfxy.modules.items.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gfxy.modules.items.entity.TYxjc;
import com.gfxy.modules.items.entity.teachingresult.TeachingResultContent;
import com.gfxy.modules.items.mapper.TYxjcMapper;
import com.gfxy.modules.items.service.ITYxjcService;
import com.gfxy.modules.items.vo.TYxjcMenberPage;
import com.gfxy.modules.excel.ExcelUtil;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 优秀教材
 * @Author: jeecg-boot
 * @Date:   2021-08-25
 * @Version: V1.0
 */
@Service
public class TYxjcServiceImpl extends AbstractProjectServiceImpl<TYxjcMapper, TYxjc> implements ITYxjcService {

	protected int memberCellNum = 4;



	private int translateClassess(String name){
		if(name == null || name.equals("")){
			return 0;
		} else if(name.equals("国家级(规划教材)")){
			return 1;
		} else if(name.equals("省级")){
			return 2;
		} else if(name.equals("校级")){
			return 3;
		} else {
			return 0;
		}

	}
	private int translateaward(String award,Integer integer) {
		if (award == null || award.equals("") || integer == 1) {
			return 0;
		} else if (award.equals("一等奖")) {
			return 1;
		} else if (award.equals("二等奖")) {
			return 2;
		}else {
			return 0;
		}
	}

	@Override
	protected String[] getMemberArray(Row row) {
		String nameStrs = ExcelUtil.formatCell(row.getCell(memberCellNum));
		return nameStrs.split(memberNameSeparator);
	}
	@Override
	protected void pass(String id, String isPass) {

	}

	@Override
	protected TYxjc getOneProject(Row row) {
		String date = ExcelUtil.formatCell(row.getCell(0));
		String classess= ExcelUtil.formatCell(row.getCell(1));
		String award  = ExcelUtil.formatCell(row.getCell(2));
		String projectName = ExcelUtil.formatCell(row.getCell(3));
		TYxjc zxjpk = new TYxjc();
		zxjpk.setDate(date);
		zxjpk.setClassess(translateClassess(classess));
		zxjpk.setAward(translateaward(award, zxjpk.getClassess()));
		zxjpk.setProjectName(projectName);
		zxjpk.setTotalScore(getTotalScore(zxjpk));
		zxjpk.setIsPass(0);
		System.out.println("zxjpk = " + zxjpk);
		return zxjpk;
	}

	@Override
	public Double getTotalScore(TYxjc tYxjc) {
		int award = tYxjc.getAward();
		int classess=tYxjc.getClassess();
		double result = 0.0;
		if (classess == 1) {
			result = 150;
		} else if (classess == 2) {
			if (award == 1) {
				result = 100;
			} else if (award == 2) {
				result = 50;
			}
		} else if (classess == 3) {
			if (award == 1) {
				result = 20;
			} else if (award == 2) {
				result = 10;
			}
		}
		return result;
	}

	@Override
	public IPage<TYxjcMenberPage> getTYxjcMemberPageListByYear(String date, Integer pageNo, Integer pageSize) {
		Page<TYxjcMenberPage> page = new Page<>(pageNo,pageSize);
		return page.setRecords(this.baseMapper.selectTYxjcMemberPageListByYear(date));
	}

	@Override
	public List<TYxjcMenberPage> getTYxjcMemberPageListByYear(String date) {
		return this.baseMapper.selectTYxjcMemberPageListByYear(date);
	}

	@Override
	protected List<TeachingResultContent> createTeachingResultContent(TYxjc jxcg)  {

		List<TeachingResultContent> result = new ArrayList<>();

		// 类型
		TeachingResultContent classTeachingResultContent = new TeachingResultContent();
		classTeachingResultContent.setType(1);
		classTeachingResultContent.setLevel(jxcg.getClassess());

		try {
			classTeachingResultContent.setValue(dictTranslater.getDictValue(TYxjcMenberPage.class, "classess", String.valueOf(jxcg.getClassess())));
			result.add(classTeachingResultContent);
		} catch (NoSuchFieldException e) {
			log.error(e.getMessage(),e);
		}

		//奖项
		TeachingResultContent awardTeachingResultContent = new TeachingResultContent();
		awardTeachingResultContent.setType(1);
		awardTeachingResultContent.setLevel(jxcg.getAward());
		try {
			awardTeachingResultContent.setValue(dictTranslater.getDictValue(TYxjcMenberPage.class, "award", String.valueOf(jxcg.getAward())));
			result.add(awardTeachingResultContent);
		} catch (NoSuchFieldException e) {
			log.error(e.getMessage(),e);
		}

		return result;
	}


}
